﻿using Microsoft.Extensions.Configuration;
using SmartWMS.Common.Config.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SmartWMS.Common.Config
{

    //public class AppSettings
    //{
    //    private AppSettings()
    //    { }

    //    public static AppSettings Config { set; get; } = default!;

    //    public ConnectionStrings ConnectionStringDto { get; set; }

    //    public static void Init(IConfiguration configuration)
    //    {
    //        Config = new AppSettings();
    //        configuration.Bind(Config);
    //    }
    //}

    /// <summary>
    /// 读取appsettings.json 里面配置信息，封装成对象返回
    /// </summary>
    public class AppSettings
    {
        public static ConnectionStringDto AppConfigOwn { get; private set; }

        /// <summary>
        /// 将配置项的值赋值给属性
        /// </summary>
        /// <param name="configuration"></param>
        public static void Initial(IConfiguration configuration)
        {


            //使用冒号来获取内层的配置项
            ConnectionStringDto myconfig = new ConnectionStringDto();
            myconfig.MSSql = configuration["ConnectionStrings:MSSql"];
            myconfig.Port = configuration["Redis:Port"];
            myconfig.Secret = configuration["Jwt:Secret"];
            myconfig.Url = configuration["Redis:Url"];
            AppConfigOwn = myconfig;
        }
    }
}

